package com.jh3502.vivo.function;

import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;
import com.jh3502.vivo.utils.SpHelper;
import com.jh3502.vivo.utils.Utils;

import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class MainPresenter extends BasePresenter<MainPresenter.MainView> {
    MainModel mMainModel;

    MainView mMainView;


    public void setMainView(MainView mMainView) {
        this.mMainView = mMainView;
    }


    public void toGetUser(Map<String, Object> body) {
        mMainView.showLoadingDialog();
        if (mMainModel == null) {
            mMainModel = new MainModel(mMainView.getActContext());
        }

        mMainModel.getUser(body, new BaseCallback(mMainView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {
                SpHelper.getInstance().saveUser(Utils.getInstance().jso2map(baseJson.getObj().toString()));
                mMainView.getUserSuccess();
            }
        });
    }

    public void toFindUnreadSum() {
        mMainView.showLoadingDialog();
        if (mMainModel == null) {
            mMainModel = new MainModel(mMainView.getActContext());
        }

        mMainModel.findUnreadSum(new BaseCallback(mMainView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {
                mMainView.findUnreadSumSuccess(Utils.getInstance().jso2map(baseJson.getObj().toString()));
            }
        });
    }


    @Override
    public void cancelCall() {

    }

    public interface MainView extends BaseView {
        void getUserSuccess();

        void findUnreadSumSuccess(Map<String, Object> map);
    }
}
